package com.graduate.service.impl;

import com.graduate.mapper.PaymentMapper;
import com.graduate.mapper.PaymentMapperCustom;
import com.graduate.po.*;
import com.graduate.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PaymentServiceImpl implements PaymentService {
    @Autowired
    private PaymentMapper paymentMapper;
    @Autowired
    private PaymentMapperCustom paymentMapperCustom;

    public List<PaymentCustom> findByPaging(Integer toPageNo) throws Exception {
        PagingVO pagingVO = new PagingVO();
        pagingVO.setToPageNo(toPageNo);
        List<PaymentCustom> list = paymentMapperCustom.findByPaging(pagingVO);
        return list;
    }
    public List<PaymentCustom> findByPagingEach(String userName) throws Exception {
        List<PaymentCustom> list = paymentMapperCustom.findByPagingEach(userName);
        return list;
    }
    public Boolean save(Payment payment) throws Exception {
        paymentMapper.insert(payment);
        // todo
        return true;
    }

    public void updateBalance(Payment payment) throws Exception {
        paymentMapperCustom.updateBalance(payment);
    }

    //返回缴费记录总数
    public int getUserCount() throws Exception {
        //自定义查询对象
        PaymentExample payment = new PaymentExample();
        //通过criteria构造查询条件
        PaymentExample.Criteria criteria = payment.createCriteria();
        criteria.andUseridIsNotNull();

        return (int)paymentMapper.countByExample(payment);
    }
    // 返回某个用户的缴费记录总数
    public int getPaymentCountByUserName(String userName) throws Exception {
        return paymentMapperCustom.findPaymentCountByUserName(userName);
    }
    public int getPaymentCountByUserID(Integer userID) throws Exception {
        return paymentMapperCustom.getPaymentCountByUserID(userID);
    }
    public List<PaymentCustom> findByPagingEachByID(Integer id, Integer toPageNo) throws Exception {
        PagingVO pagingVO = new PagingVO();
        pagingVO.setToPageNo(toPageNo);
        List<PaymentCustom> list = paymentMapperCustom.findByPagingEachByID(id, pagingVO);
        return list;
    }
}
